home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / inkey4c.zip / INKEY.DOC < prev    next >
Text File  |  1993-03-17  |  15KB  |  337 lines

  1.  
  2.  
  3.      ╔═══════════════════════════════════════════════════════════════╗
  4.      ║                   INKEY () version 1.0                        ║
  5.      ║                                                               ║
  6.      ║          Copyright 1993 by John H. Traphofner, Esq.           ║
  7.      ║                   all rights reserved                         ║
  8.      ╚═══════════════════════════════════════════════════════════════╝
  9.  
  10.  
  11.  
  12.  
  13.  
  14.      ╔═══════════════════════════════════════════════════════════════╗
  15.      ║                   SIMPLE LICENCE AGREEMENT                    ║
  16.      ╚═══════════════════════════════════════════════════════════════╝
  17.  
  18.      You can use Inkey() for as long as you like. However, before you can sell
  19.      any program developed with inkey(), you must send  a REGISTERED version of
  20.      that program to me at the address below.  If you would like the source code
  21.      for inkey(), send $5.00 (U.S.) to:
  22.  
  23.                          John H. Traphofner
  24.                          Route 1 Box 18 TT
  25.                          Interlachen, Florida  32148
  26.  
  27.      I will send you a 5 1/4 inch disk with the latest version of this utility
  28.      and the source code. I will also include any other shareware programs I
  29.      might be working on at the time.  If you want assistance with the utility
  30.      or if you have any comments or suggestions, I can be reached at:
  31.  
  32.                           DR. SNED'S RBBS
  33.                           904-325-6558
  34.  
  35.                           FIDO NET 1:3649/15
  36.  
  37.      The BBS is a free access BBS and has 12 CDROMS on-line so please enjoy it.
  38.      Just leave a comment or message to me (Co-Sysop) or to the Sysop, letting
  39.      us know where you heard about DR. SNED'S RBBS.
  40.  
  41.  
  42.  
  43.  
  44.      ╔═══════════════════════════════════════════════════════════════╗
  45.      ║              Simple Distribution Agreement                    ║
  46.      ╚═══════════════════════════════════════════════════════════════╝
  47.  
  48.  
  49.  
  50.  
  51.      Inkey() may be freely copied or distributed so long as all of the original
  52.      files remain intact and unmodified and so long as no charge is made for the
  53.      program itself and only a nominal charge (not to exceed $3.00) is made for
  54.      copying the program.
  55.  
  56.  
  57.  
  58.               ╔══════════════════════════════════════════════╗
  59.               ║            FILES ON DISTRIBUTION DISK        ║
  60.               ╚══════════════════════════════════════════════╝
  61.  
  62.      INKEY    DOC     15219 03-17-93  This Document explaining usage/licence
  63.      INKEY    H        7956 03-16-93  Include header file for inkey()
  64.  
  65.      KEYDEMO  C        9379 03-17-93  Source code for demo of inkey() functions
  66.  
  67.      INKEY_T  OBJ      1046 03-16-93      Tiny  Model object file
  68.      INKEY_S  OBJ      1046 03-16-93      Small Model object file
  69.      INKEY_M  OBJ      1053 03-16-93      Medium Model object file
  70.      INKEY_C  OBJ      1046 03-16-93      Compact Model object file
  71.      INKEY_L  OBJ      1053 03-16-93      Large Model object file
  72.      INKEY_H  OBJ      1080 03-16-93      Huge Model object file
  73.  
  74.      KEYDEMO  COM      7594 03-17-93  Compiled version of Keydemo.C
  75.  
  76.  
  77.  
  78.  
  79.           ╔═════════════════════════════════════════════════╗
  80.           ║    unsigned int inkey(unsigned int) ;           ║
  81.           ║                                                 ║
  82.           ║    Associated global variable: KEY_WAIT         ║
  83.           ╚═════════════════════════════════════════════════╝
  84.  
  85.  
  86.      ╔═══════════════════════════════════════════════════════════════╗
  87.      ║Usage: parameter equals zero                                   ║
  88.      ║Returns the key being pressed as either an ASCII code or an    ║
  89.      ║extended code, depending on the key pressed.                   ║
  90.      ╚═══════════════════════════════════════════════════════════════╝
  91.  
  92.  
  93.      ╔═══════════════════════════════════════════════════════════════╗
  94.      ║Usage: parameter greater than zero but less than  512:         ║
  95.      ║Returns Pressed   [1] or Unpressed [0] state of the key that is║
  96.      ║specified by the code in the parameter.                        ║
  97.      ╚═══════════════════════════════════════════════════════════════╝
  98.  
  99.      ╔═══════════════════════════════════════════════════════════════╗
  100.      ║Usage: parameter equals 512:                                   ║
  101.      ║Returns True for the presence of an Extended 101 keyboard or   ║
  102.      ║        False if non-extended keyboard is present.             ║
  103.      ╚═══════════════════════════════════════════════════════════════╝
  104.  
  105.      ╔═══════════════════════════════════════════════════════════════╗
  106.      ║Usage parameter > 512                                          ║
  107.      ║Returns True or False for ON/OFF or Pressed/NotPressed State   ║
  108.      ║of the special keys and key states left Ctrl, Right Ctrl, Left ║
  109.      ║Alt, Right Alt, Numlock, Scroll Lock, CapsLock left and right  ║
  110.      ║shift, Insert ON / OFF , CAPSLOCK  ON / OFF and NUMLOCK ON /   ║
  111.      ║OFF.                                                           ║
  112.      ╚═══════════════════════════════════════════════════════════════╝
  113.  
  114.  
  115.  
  116.           INKEY is a utility for reading the keyboard in 'C' language programs.
  117.      With it, you can include all possible key board combinations into your
  118.      program.  Checking for a Page Down key press is as easy as writing:
  119.  
  120.           if( inkey(PGDN) )
  121.  
  122.      If the Page Down Key is pressed, the function will evaluate to TRUE , if
  123.      not pressed, it evaluates to FALSE.
  124.  
  125.      Not all keys are available on all keyboards.  To check for the Extended 101
  126.      keyboard in your program, use the following:
  127.  
  128.           if( inkey(STATUS) )     or   if( inkey(READ_101_KEY) )
  129.  
  130.      The function evaluates to TRUE if a 101 keyboard is present and to FALSE
  131.      for the non-extended older 84 key keyboards.
  132.  
  133.      To read what key is being pressed, use the following:
  134.  
  135.      keyin = inkey(READ_KEY);
  136.  
  137.      keyin will then be equal to the key code being pressed or to zero if no key
  138.      is being pressed. If an 'A' is being pressed, inkey(READ_KEY) will return a
  139.      65 , the ASCII code for a capital 'A'. If the F1 key is being pressed,
  140.      inkey(READ_KEY) will return a code of 315 [ 59 EXTENDED ] The inkey.h file
  141.      contains #defines that you might find useful.
  142.  
  143.      Checking for a function key such as F1 could be done this way:
  144.  
  145.           unsigned int keyin;
  146.  
  147.           keyin = inkey(READ_KEY);
  148.  
  149.           if (keyin == F1) printf("You pressed the F1 key");
  150.  
  151.      Or if you choose, it could be done this way:
  152.  
  153.           if(inkey(F1)) printf("You pressed the F1 key");
  154.  
  155.      Or, if you like obscure numbers to obfuscate your code:
  156.  
  157.           if(inkey(315)) printf("You have pressed the 315 [F1] key");
  158.  
  159.  
  160.           The inkey() function is not an input function that waits forever for a
  161.      key to be pressed before moving on.  In fact, inkey is so quick to move on,
  162.      that it would miss most keypresses if it were not for the use of the global
  163.      variable KEY_WAIT .  This variable controls the number of times the inkey
  164.      routine will poll the keyboard for a character before deciding that no key
  165.      is available.  KEY_WAIT defaults to 2048.  Rather on the high side. You
  166.      will have to experiment in your application for the right number.  Too low
  167.      and you might not read the keypress, too high and you program can bog down
  168.      polling the key board.
  169.  
  170.           However, there are times when you would rather NOT move on until a key
  171.      is pressed. Rather than be limited the number of polls in an unsigned int,
  172.      you can wait forever by setting KEY_WAIT to 0.
  173.      Doing this will suspend the operation of the program until a key is
  174.      pressed.  "Press any key to continue" Could be written as :
  175.  
  176.                printf("Press any key to continue");
  177.                KEY_WAIT = 0;
  178.                inkey(READ_KEY);
  179.  
  180.           There are several other keys and key 'STATES' or 'STATUS' that inkey
  181.      can check. On a non-extended keyboard, inkey can check for the following:
  182.  
  183.      ALT_PRESSED     CTRL_PRESSED  LSHIFT_PRESSED  RSHIFT_PRESSED
  184.  
  185.      SHIFT_PRESSED [ either left or right ]
  186.  
  187.      These keys can not be checked using the inkey(READ_KEY) call but must
  188.      instead be called by name such as inkey(ALT_PRESSED) or
  189.      inkey(SHIFT_PRESSED). The TRUE / FALSE [1/0] result is returned by these
  190.      calls.
  191.  
  192.           The non-extended keyboard can also be checked with inkey for the
  193.      following keyboard STATES:
  194.  
  195.           INS_ON          CAPSLOCK_ON        NUMLOCK_ON
  196.  
  197.      if( inkey(NUMLOCK_ON) ) printf("Your NumLock is toggled ON");
  198.  
  199.      On an extended 101 keyboard, the following are also available:
  200.  
  201.      SYSREQ_PRESSED  CAPSLOCK_PRESSED  NUMLOCK_PRESSED  SCROLL_PRESSED
  202.      R_ALT_PRESSED   R_CTRL_PRESSED    L_ALT_PRESSED    L_CTRL_PRESSED
  203.  
  204.      Another use for the special key handling ability of inkey() is those handy
  205.      three key combinations Such as CTRL-ALT-Q .  Three key combinations are
  206.      great for applications because the chances of accidently pressing that
  207.      combination is slim compared to an 'E' for Exit or even the 'ESC' key.  An
  208.      example of checking for three keys is found in the file KEYDEMO>C.
  209.  
  210.      do
  211.      {              .....
  212.                     .....
  213.                     printf("Press Control-ALT-Q to quit");
  214.  
  215.      }while ( ! (inkey(CTRL_PRESSED) && inkey(ALT_Q) )  );
  216.  
  217.  
  218.      The loop will keep executing so long as there is no Ctrl-Alt-Q pressed.                                              ALT_F10·····
  219.                INKEY APPENDIX                ALT_F11·····
  220.              OF DEFINE NAMES USED            ALT_F12········
  221.                  IN INKEY.H                  ALT_F1······
  222.                                              ALT_F2······
  223.           SPECIAL KEYS AND STATUS            ALT_F3······
  224.                                              ALT_F4······
  225.      ╔══════════════════════════════╗        ALT_F5······
  226.      ║         ALT_PRESSED          ║        ALT_F6······
  227.      ║         CAPSLOCK_ON          ║        ALT_F7······
  228.      ║         CAPSLOCK_PRESSED     ║        ALT_F8······
  229.      ║         CTRL_PRESSED         ║        ALT_F9······
  230.      ║         INS_ON········       ║        ALT_G
  231.      ║         L_ALT_PRESSED··      ║        ALT_HOME·······
  232.      ║         L_CTRL_PRESSED··     ║        ALT_H·········
  233.      ║         LSHIFT_PRESSED       ║        ALT_I
  234.      ║         NUMLOCK_ON·····      ║        ALT_INS········
  235.      ║         NUMLOCK_PRESSED·     ║        ALT_J
  236.      ║         R_ALT_PRESSED···     ║        ALT_K
  237.      ║         R_CTRL_PRESSED··     ║        ALT_L
  238.      ║         RSHIFT_PRESSED       ║        ALT_LBRACKET··
  239.      ║         SCROLL_PRESSED··     ║        ALT_LEFT·······
  240.      ║         SHIFT_PRESSED·       ║        ALT_M
  241.      ║         SYSREQ_PRESSED··     ║        ALT_MINUS···
  242.      ╚══════════════════════════════╝        ALT_N
  243.                                              ALT_NUM_ENTER··
  244.                                              ALT_NUM_MINUS·
  245.                                              ALT_NUM_PLUS··
  246.      EXTENDED AND NON STANDARD KEYS          ALT_NUM_SLASH··
  247.           ·······                            ALT_O
  248.           ·······                            ALT_P
  249.      ALT_0·······                            ALT_PERIOD
  250.      ALT_1·······                            ALT_PGDN·······
  251.      ALT_2·······                            ALT_PGUP·······
  252.      ALT_3·······                            ALT_Q
  253.      ALT_4·······                            ALT_R
  254.      ALT_5·······                            ALT_RBRACKET
  255.      ALT_6·······                            ALT_RIGHT······
  256.      ALT_7                                   ALT_S
  257.      ALT_8                                   ALT_SEMICOLON·
  258.      ALT_9                                   ALT_SLASH
  259.      ALT_A                                   ALT_TAB········
  260.      ALT_ACCENT                              ALT_T·
  261.      ALT_APOSTROPHE·                         ALT_UP·········
  262.      ALT_ASTERIK                             ALT_U·
  263.      ALT_B                                   ALT_V
  264.      ALT_BACK·                               ALT_W
  265.      ALT_BREAK                               ALT_X
  266.      ALT_BSLASH                              ALT_Y·
  267.      ALT_C                                   ALT_Z
  268.      ALT_COMMA                               BACKSPACE
  269.      ALT_D                                   BREAK_KEY
  270.      ALT_DEL········                         CAPSLOCK
  271.      ALT_DOWN·······                         CENTER
  272.      ALT_E                                   CTRL_@
  273.      ALT_END    ···                          CTRL__
  274.      ALT_ENTER                               CTRL_A
  275.      ALT_EQUAL···                            CTRL_B
  276.      ALT_ESC                                 CTRL_BACKSLASH
  277.      ALT_F                                   CTRL_C      CTRL_CARAT                              F10
  278.      CTRL_D                                  F11·········
  279.      CTRL_DEL·······                         F12·········
  280.      CTRL_DOWN······                         F2
  281.      CTRL_E                                  F3
  282.      CTRL_END····                            F4
  283.      CTRL_F                                  F5
  284.      CTRL_F1                                 F6
  285.      CTRL_F10····                            F7
  286.      CTRL_F11····                            F8
  287.      CTRL_F12····                            F9
  288.      CTRL_F2                                 HOME
  289.      CTRL_F3                                 INS
  290.      CTRL_F4·······                          LEFT
  291.      CTRL_F5·····                            NUMLOCK
  292.      CTRL_F6·····                            PGDN
  293.      CTRL_F7·····                            PGUP
  294.      CTRL_F8·····                            RIGHT
  295.      CTRL_F9·····                            SCROLL_LOCK···
  296.      CTRL_G                                  SHIFT_F1
  297.      CTRL_H                                  SHIFT_F10
  298.      CTRL_HOME···                            SHIFT_F11···
  299.      CTRL_I                                  SHIFT_F12···
  300.      CTRL_INS·······                         SHIFT_F2
  301.      CTRL_J                                  SHIFT_F3
  302.      CTRL_K                                  SHIFT_F4
  303.      CTRL_L                                  SHIFT_F5
  304.      CTRL_LBRACKET·                          SHIFT_F6
  305.      CTRL_LEFT···                            SHIFT_F7
  306.      CTRL_M                                  SHIFT_F8
  307.      CTRL_N                                  SHIFT_F9·
  308.      CTRL_NUM_ASTERICK                       SHIFT_TAB
  309.      CTRL_NUM_MINUS·                         SPACEBAR
  310.      CTRL_NUM_PLUS··                         TAB
  311.      CTRL_NUM_SLASH·                         UP
  312.      CTRL_O·
  313.      CTRL_P
  314.      CTRL_PGDN···
  315.      CTRL_PGUP···
  316.      CTRL_PRINT··
  317.      CTRL_Q
  318.      CTRL_R
  319.      CTRL_RBRACKET
  320.      CTRL_RIGHT··
  321.      CTRL_S
  322.      CTRL_T
  323.      CTRL_U
  324.      CTRL_UP········
  325.      CTRL_V
  326.      CTRL_W
  327.      CTRL_X
  328.      CTRL_Y
  329.      CTRL_Z
  330.      DEL
  331.      DELETE·· ···
  332.      DOWN
  333.      END
  334.      ENTER
  335.      ESC
  336.      F1
  337.